

import java.awt.* ;
//import java.awt.event.* ;
import java.awt.image.BufferedImage;

/** Lightweight panel that is the perfect size of given image. <p>

    - - - - - - - - - - - - - - - - - <p>

    Copyright (c) 1998-2004 Paul Wheaton <p>

    You are welcome to do whatever you want to with this source file provided
    that you maintain this comment fragment (between the dashed lines).
    Modify it, change the package name, change the class name ... personal or business
    use ...  sell it, share it ... add a copyright for the portions you add ... <p>

    My goal in giving this away and maintaining the copyright is to hopefully direct
    developers back to JavaRanch. <p>

    The original source can be found at <a href=http://www.javaranch.com>JavaRanch</a> <p>

    - - - - - - - - - - - - - - - - - <p>
 * modified by Dark_Wolf aka David Hansen
 

    @author Paul Wheaton
*/
public class ImagePanel extends Container
{

    private BufferedImage image = null ;
    private int height;
    private int width;

   

    
    
    public ImagePanel( BufferedImage image , int maxWidth, int maxHeight )
    {
        if (image.getHeight() > maxHeight || image.getWidth() > maxWidth)
            this.image = AlbumHelper.scale(image, maxWidth > maxHeight ? maxWidth : maxHeight);
       else
            this.image = image;
        
        height = image.getHeight(null);
        width = image.getWidth(null);
        setBounds(0, 0, width, height);
            
    }

    public ImagePanel( BufferedImage image )
    {
        this.image = image ;
        height = image.getHeight(null);
        width = image.getWidth( null );
        setBounds( 0 , 0 ,width ,height);
    }
    
    public void setImage(BufferedImage image)
    {
        this.image = image;
        height = image.getHeight();
        width = image.getWidth( null );
        setBounds(0,0,width , height );
        repaint();
    }
    
    public void setImage(BufferedImage image, int maxWidth, int maxHeight)
    {
        if (image.getHeight() > maxHeight || image.getWidth() > maxWidth) {
            this.image = AlbumHelper.scale(image, maxWidth);
        } else {
            this.image = image;
        }
        height = this.image.getHeight();
        width = this.image.getWidth();
        setBounds(0, 0, width, height);
        repaint();
    }

   public void setMaxSize(int maxWidth, int maxHeight)
   {
       if (image.getHeight() > maxHeight || image.getWidth() > maxWidth) {
            image = AlbumHelper.scale(image, maxWidth);
            height = image.getHeight();
            width = image.getWidth();
            setBounds(0, 0, width, height);
            repaint();
        } 
        
   }

    

    /** For internal use only. <p>
    */
    @Override
    public Dimension getPreferredSize()
    {
        return new Dimension( width , height );
    }

    @Override
    public void update( Graphics g )
    {
        paint( g );
    }

    /** For internal use only. <p>
    */
    @Override
    public void paint( Graphics g )
    {
        g.drawImage( image , 0 , 0 , null );
        super.paint( g );
    }

}




